Skip to content

Conversation

@standage
Copy link
Member

@standage standage commented Dec 10, 2025

This PR adds support for renaming samples in the process of copying. Sample names are current specified one of two ways: as a list of string arguments...

s1 s2 s3

...or as a file containing one sample name for each line.

s1
s2
s3

This update allows sample renaming in both cases. For lists of string arguments, this is done by specifying the old name and new name separated by a colon.

s1:Sample1 s2:Sample2 s3:Sample3

For sample name files, this is done by adding a new column with a tab-separated value.

s1    Sample1
s2    Sample2
s3    Sample3

# -------------------------------------------------------------------------------------------------


class NameMap(dict):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class handles parsing sample names from argument lists or files.

Comment on lines -108 to +110
yield FastqFile(source_path, sample_name, read, self.prefix)
new_name = self.sample_name_map[sample_name]
yield FastqFile(source_path, new_name, read, self.prefix)
Copy link
Member Author

@standage standage Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the only place where the new sample name is used. All the other changes in this file are variable name changes that don't really affect how the code works.

ezfastq/cli.py Outdated
Comment on lines 48 to 56
epilog_text = """
Examples:
ezfastq /path/to/fastqs/ sample1 sample2 sample3
ezfastq /path/to/fastqs/ s1:Sample1 s2:Sample2 s3:Sample3
ezfastq /path/to/fastqs/ samplenames.txt
ezfastq /path/to/fastqs/ samplenames.txt --workdir /path/to/projectdir/ --subdir seq/Run01/
ezfastq /path/to/fastqs/ samplenames.txt --pair-mode 2
"""
epilog = Text(epilog_text, no_wrap=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an epilog to the argument parser since showing examples is the best way to describe how the sample renaming is done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has unit tests for the new NameMap class.

Comment on lines +149 to +152
def test_copier_with_renaming(tmp_path):
sample_names = NameMap.from_arglist(
["test1:TestSampleA", "test2:TestSampleB", "test3:TestSampleC"]
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added a test for the FastqCopier test to make sure it renames files correctly on copy.

@standage standage requested a review from andhamel December 11, 2025 00:39
@andhamel
Copy link

andhamel commented Dec 11, 2025

This looks great! I've grown to really appreciate instantiating classes with classmethods. It seems to provide a lot more flexibility, i.e. from file or arglist than with one function containing a lot of logic statements.

@standage standage merged commit 0b1a39e into main Dec 12, 2025
4 checks passed
@standage standage deleted the rename branch December 12, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants